package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type Video struct {
	gorm.Model
	UserId int    `gorm:"type:int" json:"userId"`
	Status int    `gorm:"type:int" json:"status"`
	Title  string `gorm:"type:varchar(30)" json:"Title"`
	Image  string `gorm:"type:varchar(30)" json:"image"`
	Refer  string `gorm:"type:varchar(30)" json:"refer"`
}
type HisTory struct {
	gorm.Model
	UserId  int `gorm:"type:int" json:"userId"`
	VideoId int `gorm:"type:int" json:"status"`
}

func (v *Video) GetVideoList(db *gorm.DB) (list []*__.VideoItem, err error) {
	err = db.Model(&v).
		Select("id,title,image,refer").Find(&list).Error
	return
}
func (h *HisTory) GetHistory(db *gorm.DB) (list []*__.Item, err error) {
	err = db.Model(&h).
		Select("username,title").
		Joins("LEFT JOIN users ON users.id = his_tories.user_id").
		Joins("LEFT JOIN videos ON videos.id = his_tories.video_id").
		Find(&list).Error
	return
}
